package com.kyzh.core.pager.weal.community

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.kyzh.core.R
import com.gushenge.core.base.activity.BaseActivity
import com.kyzh.core.databinding.ActCommunitynewsBinding

class CommunityNewsActivity : BaseActivity() {
    companion object{
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, CommunityNewsActivity::class.java)
            context.startActivity(starter)
        }
    }
    private lateinit var db :ActCommunitynewsBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        db = DataBindingUtil.setContentView(this, R.layout.act_communitynews)
        initTab()
    }
    private val titles = arrayListOf("互动消息","我的帖子")
    private val fragments = arrayListOf(NewsFragment(),MyNewsFragment())
    private fun initTab() {
        val mediator  = TabLayoutMediator( db.tab, db. viewpager) { tab, position -> //这里可以自定义TabView
            tab.text =titles[position]
        }
        db.viewpager.adapter=object : FragmentStateAdapter(this){
            override fun getItemCount()=2
            override fun createFragment(position: Int)= fragments[position]
        }
        mediator.attach()
    }
}